/*
 * CpuDebug.java
 *
 * Created on 6 de Dezembro de 2007, 23:31
 */

package com.google.code.jbrnes.presentation;

import com.google.code.jbrnes.core.Cpu;
import com.google.code.jbrnes.core.CpuCode;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author  Leandro
 */
public class CpuDebug extends javax.swing.JFrame {
    
    /** Creates new form CpuDebug */
    public CpuDebug() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtA = new javax.swing.JTextField();
        jchkCarry = new javax.swing.JCheckBox();
        jchkZero = new javax.swing.JCheckBox();
        jchkInterrupt = new javax.swing.JCheckBox();
        jchkDecimal = new javax.swing.JCheckBox();
        jchkBreak = new javax.swing.JCheckBox();
        jchkUnused = new javax.swing.JCheckBox();
        jchkOverflown = new javax.swing.JCheckBox();
        jchkSign = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtX = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtY = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtS = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtPC = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtSP = new javax.swing.JTextField();
        jbtRefresh = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtxtAsm = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Debug - CPU");
        setResizable(false);

        jLabel1.setText("CPU: 6052");

        jchkCarry.setText("Carry");
        jchkCarry.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jchkCarryActionPerformed(evt);
            }
        });

        jchkZero.setText("Zero");

        jchkInterrupt.setText("Interrupt");

        jchkDecimal.setText("Decimal");
        jchkDecimal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jchkDecimalActionPerformed(evt);
            }
        });

        jchkBreak.setText("Break");

        jchkUnused.setText("Unused");

        jchkOverflown.setText("Overflown");

        jchkSign.setText("Sign");

        jLabel2.setText("ACC");

        jLabel3.setText("X");

        jLabel4.setText("Y");

        jLabel5.setText("S");

        jLabel6.setText("PC");

        txtPC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPCActionPerformed(evt);
            }
        });

        jLabel7.setText("SP");

        txtSP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSPActionPerformed(evt);
            }
        });

        jbtRefresh.setText("Refresh");
        jbtRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtRefreshActionPerformed(evt);
            }
        });

        jtxtAsm.setColumns(20);
        jtxtAsm.setRows(5);
        jScrollPane1.setViewportView(jtxtAsm);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel1))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jchkCarry)
                                            .addComponent(jchkDecimal)
                                            .addComponent(jchkOverflown))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jchkZero)
                                                    .addComponent(jchkBreak))
                                                .addGap(4, 4, 4)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jchkUnused)
                                                    .addComponent(jchkInterrupt)))
                                            .addComponent(jchkSign)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(txtY)
                                            .addComponent(txtA)
                                            .addComponent(txtX, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(54, 54, 54)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(jLabel7))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(txtS)
                                            .addComponent(txtSP)
                                            .addComponent(txtPC, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(16, 16, 16)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(423, Short.MAX_VALUE)
                        .addComponent(jbtRefresh)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(7, 7, 7)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jchkCarry)
                            .addComponent(jchkZero)
                            .addComponent(jchkInterrupt))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jchkDecimal)
                            .addComponent(jchkBreak)
                            .addComponent(jchkUnused))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jchkOverflown)
                            .addComponent(jchkSign))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtRefresh)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-512)/2, (screenSize.height-388)/2, 512, 388);
    }// </editor-fold>//GEN-END:initComponents

    private void jchkCarryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jchkCarryActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jchkCarryActionPerformed

    private void jchkDecimalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jchkDecimalActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jchkDecimalActionPerformed

    private void txtPCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPCActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtPCActionPerformed

    private void txtSPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSPActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtSPActionPerformed

    private void jbtRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtRefreshActionPerformed
        try {
            Cpu.init();
            // TODO add your handling code here:
            jchkBreak.setSelected(Cpu.fBreak);
            jchkCarry.setSelected(Cpu.fCarry);
            jchkDecimal.setSelected(Cpu.fDecimal);
            jchkInterrupt.setSelected(Cpu.fInterrupt); 
            jchkOverflown.setSelected(Cpu.fOverflow);
            jchkSign.setSelected(Cpu.fNegativeSign);
            jchkUnused.setSelected(Cpu.fUnused);
            jchkZero.setSelected(Cpu.fZero);
            
            txtA.setText(Integer.toHexString(Cpu.regAccumulator));
            txtPC.setText(Integer.toHexString(Cpu.regProgramCounter));
            txtS.setText(Integer.toHexString(Cpu.getRegStatus()));
            txtSP.setText(Integer.toHexString(Cpu.regStackPointer));
            txtX.setText(Integer.toHexString(Cpu.regIndexX));
            txtY.setText(Integer.toHexString(Cpu.regIndexY));
            
            
            
            
        } catch (Exception ex) {
            Logger.getLogger(CpuDebug.class.getName()).log(Level.SEVERE, null, ex);
        }
        
}//GEN-LAST:event_jbtRefreshActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CpuDebug().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtRefresh;
    private javax.swing.JCheckBox jchkBreak;
    private javax.swing.JCheckBox jchkCarry;
    private javax.swing.JCheckBox jchkDecimal;
    private javax.swing.JCheckBox jchkInterrupt;
    private javax.swing.JCheckBox jchkOverflown;
    private javax.swing.JCheckBox jchkSign;
    private javax.swing.JCheckBox jchkUnused;
    private javax.swing.JCheckBox jchkZero;
    private javax.swing.JTextArea jtxtAsm;
    private javax.swing.JTextField txtA;
    private javax.swing.JTextField txtPC;
    private javax.swing.JTextField txtS;
    private javax.swing.JTextField txtSP;
    private javax.swing.JTextField txtX;
    private javax.swing.JTextField txtY;
    // End of variables declaration//GEN-END:variables
    
}
